package persistence;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil{
 private static final SessionFactory sessionFactory = buildSessionFactory();
 
 private static SessionFactory buildSessionFactory(){
  try{
   AnnotationConfiguration cfg = new AnnotationConfiguration();
   cfg.configure("/persistence/hibernate.cfg.xml");
   return cfg.buildSessionFactory();
  }catch(Throwable e) {
   System.out.println("Criacao do Objeto SessionFactory Falhou. Erro: "+e);
   throw new ExceptionInInitializerError(e);
  }  
} 
public static SessionFactory getSessionFactory(){
  return sessionFactory;	 
}
public static void shutdown() {
	// Close caches and connection pools
	getSessionFactory().close();
}
}
